import 'package:flutter/material.dart';

class TabBarAways extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 4,
      child: Scaffold(
        appBar: AppBar(
          bottom: TabBar(
            tabs: [
              Tab(text: "1"),
              Tab(text: "2"),
              Tab(text: "3"),
              Tab(text: "4"),
            ],
          ),
          title: Text('Select last tab'),
        ),
        body: TabBarView(
          children: [
            TabContent(),
            TabContent(),
            TabContent(),
            TabContent(),
          ],
        ),
      ),
    );
  }
}

class TabContent extends StatefulWidget {
  @override
  _TabContentState createState() => _TabContentState();
}

class _TabContentState extends State<TabContent>
    with AutomaticKeepAliveClientMixin<TabContent> {
  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    print('initState');
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    print('build');
    super.build(context);
    return Container();
  }
}
